package wqh.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import wqh.domain.GeoBuilding;
import wqh.pojo.MapRet;
import wqh.service.GeoBuildingService;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by devts on 2016/12/2.
 */
@RestController
@CrossOrigin(origins = "*")
@RequestMapping("/water/index_page")
public class IndexPageJSONController {

    @Autowired
    private GeoBuildingService geoBuildingService;

    @RequestMapping(value = "/getArea",method = RequestMethod.GET)
    public Object getArea()
    {
        GeoBuilding g = new GeoBuilding();
        g.setLevel((byte)1);
        List<GeoBuilding> geoBuildingList = geoBuildingService.findRecordByClass2(g);
        if(geoBuildingList.size() == 0) return MapRet.DATA(null);
        List<Object> objectList = new ArrayList<Object>();
        for(GeoBuilding geoBuilding : geoBuildingList)
        {
            Map<String,Object> map = new HashMap<String,Object>();
            map.put("id",geoBuilding.getId());
            map.put("text","水压监测位置： " + geoBuilding.getName());
            objectList.add(map);
        }
        return MapRet.DATA(objectList);
    }

}
